const { toUrl,globalData } = getApp()
import { request } from '@/utils/request'
Page({
    toUrl,
    data: {
        list: [],
        integral: {}, //积分
        page: 1,
        count: 1,
        isExit: false,
        globalData,
        userInfo:{}
    },
    getList() {
        if(this.data.page > 1 && this.data.page > this.data.count) {
            this.setData({
                isExit: true
            })
            return
        }
        const that = this
        const data = {
            page: this.data.page
        }
        request('user/integrallist',{data}).then(res => {
            that.setData({
                list: that.data.list.concat(res.data),
                page: ++that.data.page,
                count: res.count
            })
            request("user/getuserinfo").then((res) => {
                if (res.errcode == 1) {
                  console.log('用户信息');
                  getApp().globalData.baseInfo = res.data
                  this.setData({
                    userInfo:getApp().globalData.baseInfo
                  })
                }
              });
        })
    },
    getIntegral() {
        const that = this
        request('integral/index').then(res => {
            that.setData({
                integral: res.data
            })
        })
    },

    
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            userInfo:getApp().globalData.baseInfo
          })
        this.getIntegral()
        this.getList()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getIntegral()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        if(this.data.isExit) {
            return
        }else {
            this.getList()
        }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})